<%@ page contentType="text/html;charset=UTF-8" language="java"  autoFlush="true" buffer="100kb" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <%@include file="/front-end/views/common/head.jsp"%>
    <title>影厅管理</title>
    <Script type="text/javascript">
        $(function () {
            $("a.glyphicon-trash").click(function () {
                // 在事件的function函数中，有一个this对象。这个this对象，是当前正在响应事件的dom对象。
                /**
                 * confirm是确认提示框函数,参数是它的提示内容
                 * 它有两个按钮，一个确认，一个是取消。返回true表示点击了，确认，返回false表示点击取消。
                 */
                return confirm("你确定要删除【" + $(this).parent().parent().find("td:first").text() + "】?");
                // return false// 阻止元素的默认行为===不提交请求
            });
        });
        function ajaxRequest(id) {
// 				1、创建XMLHttpRequest
            var xmlhttprequest = new XMLHttpRequest();
            var url = "manage/studioServlet?action=getStudio&id="+id;
// 				2、调用open方法设置请求参数
            xmlhttprequest.open("GET",url,true);
// 				4、在send方法前绑定onreadystatechange事件，处理请求完成后的操作。
            xmlhttprequest.onreadystatechange = function(){
                if (xmlhttprequest.readyState == 4 && xmlhttprequest.status == 200) {
                    // alert("收到服务器返回的数据：" + xmlhttprequest.responseText);
                    var data = JSON.parse(xmlhttprequest.responseText);
                    // alert(data.play_type_id);
                    var studio_id = document.getElementById('studio_id');
                    studio_id.value = data.studio_id;
                    var studio_col_count = document.getElementById('studio_col_count');
                    studio_col_count.value = data.studio_col_count;
                    var studio_row_count = document.getElementById('studio_row_count');
                    studio_row_count.value = data.studio_row_count;
                    var studio_introduction = document.getElementById('studio_introduction');
                    studio_introduction.value = data.studio_introduction;
                    var studio_name = document.getElementById('studio_name');
                    studio_name.value = data.studio_name;
                }
            }
            // 3、调用send方法发送请求
            xmlhttprequest.send();
        }
    </Script>


</head>
<body>
<nav class="navbar navbar-default">
  <div class="container-fluid">
      <%@include file="/front-end/views/common/manage_menu.jsp"%>
  </div>
</nav>
<div class="itemone" style="display:block;">
    <div>
    <form method="POST" action="manage/studioServlet?action=pageByName">
        &nbsp&nbsp&nbsp&nbsp影厅名称：<input type="name" name="studio_name" value="${param.studio_name}" >
        &nbsp&nbsp&nbsp&nbsp<input type="submit" value="查询" id="chaxun">
    </form>
    </div>
    <div>
        <!-- 按钮触发模态框 -->
        <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
        </button>
        <!-- 模态框（Modal） -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="myModalLabel1">
                            添加影厅
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form method="post" action="manage/studioServlet?action=add&pageNo=${requestScope.page.pageTotal}">
                          <div class="form-group">
                            <label>影厅名称：</label>
                            <input name="studio_name" type="text" class="form-control" placeholder="影片名称">
                          </div>
                          <div class="form-group">
                            <label>行数：</label>
                            <input type="text" readonly="readonly" value="5" class="form-control" placeholder="行数">
                          </div>
                        <div class="form-group">
                            <label>列数：</label>
                            <input type="text" readonly="readonly" value="5" class="form-control" placeholder="列数">
                        </div>
                            <div class="form-group">
                            <label>简介：</label>
                            <input name="studio_introduction" type="text" class="form-control" placeholder="简介">
                          </div>
                            <input type="submit" class="btn btn-primary" value="提交">
                        </form>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                        </button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>

    </div>



    <div>
        <div class="modal fade" id="myModaledit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="myModalLabel2">
                            修改影厅
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form method="post" action="manage/studioServlet?action=update&pageNo=${requestScope.page.pageNo}">
                            <input id="studio_id" name="studio_id" type="hidden">
                            <div class="form-group">
                                <label>影厅名称：</label>
                                <input id="studio_name" name="studio_name" type="text" class="form-control" placeholder="影厅名称">
                            </div>
                            <div class="form-group">
                                <label>行数：</label>
                                <input id="studio_row_count" name="studio_row_count" type="text" readonly="readonly" value="5" class="form-control" placeholder="行数">
                            </div>
                            <div class="form-group">
                                <label>列数：</label>
                                <input name="studio_col_count" id="studio_col_count" type="text" readonly="readonly" value="5" class="form-control" placeholder="列数">
                            </div>
                            <div class="form-group">
                                <label>简介：</label>
                                <input id="studio_introduction" name="studio_introduction" type="text" class="form-control" placeholder="简介">
                            </div>
                            <input type="submit" vulue="提交" class="btn btn-primary">
                        </form>

                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                        </button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>

    </div>



    <table class="table table-hover">
        <thead>
            <tr style="height: 12px;">
                <th>影厅id</th>
                <th>影厅名称</th>
                <th>行数</th>
                <th>列数</th>
                <th>影厅简介</th>
                <th>影厅状态</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
        <input type="hidden" title="${requestScope.page.items.size()}">

        <c:forEach items="${requestScope.page.items}" var="item" >
            <tr>
                <input type="hidden" title="${item.toString()}">
                <td>${item.studio_id}</td>
                <td>${item.studio_name}</td>
                <td>${item.studio_row_count}</td>
                <td>${item.studio_col_count}</td>
                <td>${item.studio_introduction}</td>
                <c:if test="${item.studio_flag ==1}">
                    <td>已生成座位</td>
                </c:if>
                <c:if test="${item.studio_flag ==0}">
                    <td><a href="manage/studioServlet?action=setSeat&studio_id=${item.studio_id}&pageNo=${requestScope.page.pageNo}">点击生成座位</a></td>
                </c:if>
                <td>
                      <a data-target="#myModaledit" data-toggle="modal" onclick="ajaxRequest('${item.studio_id}')" data-target="#myModaledit" class="glyphicon glyphicon-edit" aria-hidden="true"></a>
                      <a class="glyphicon glyphicon-option-vertical" aria-hidden="true"></a>
                      <a id="delete" href="manage/studioServlet?action=delete&id=${item.studio_id}&pageNo=${requestScope.page.pageNo}" class="glyphicon glyphicon-trash" aria-hidden="true"></a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
<%@include file="/front-end/views/common/page_nav.jsp"%>
        </div>
 <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous">
        $('#myModal').on('shown.bs.modal', function () {
          $('#myInput').focus()</html>
        })
    </script>
 <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>

</body>
